home *** CD-ROM | disk | FTP | other *** search
- Path: jaxnet.jaxnet.com!jax!garyg
- From: garyg@jax.jaxnet.com (Gary M. Greenberg)
- Newsgroups: comp.lang.c
- Subject: Re: Command line Arguments
- Date: 5 Feb 1996 22:29:46 GMT
- Organization: Southeast Network Services, Inc.
- Message-ID: <4f60cr$34v@jaxnet.jaxnet.com>
- References: <4f2qev$9jq@cloner3.netcom.com>
- NNTP-Posting-Host: jax.jaxnet.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Glen 'Steve' Vandiver (buxx@ix.netcom.com) wrote:
- : Hi! I have been haveing trouble with my commandline arguements. I have
- : it too where i can read the entire argument string after the run. No
- : prob. but lets say i want it to split it up like this. the first word
- : goes into char *user; and the rest goes into char *command;. HOW WOULD
- : I DO THIS? thanx! bye!
-
- I think this is what you mean:
-
- #include <stdio.h>
- #include <string.h>
- #define LEN 256
- int main (int argc,char **argv)
- {
-
- char user[LEN], command[LEN*4];
- int i;
- if(argc<3) {
- printf("Enter more command line args. Bye\n");
- exit (1);
- }
- strcpy(user,argv[1]);
- for(i=2;i<argc;i++)
- strcat(command,argv[i]);
- printf("User: %s\tCommand: %s\n",user,command);
- return 0;
- }
-
- gary /* the Sorcerer's Apprentice */
-
- "Why do we have to hide from the police, Daddy?"
- "Because we use vi, honey. They use emacs."
- "Unless we're on the Mac. Then we use BBEdit 'cause 'It doesn't suck.'"
-